package com.gerenboke.controller;

import com.gerenboke.domain.ResponseResult;
import com.gerenboke.domain.entity.Link;
import com.gerenboke.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    @GetMapping("/list")
    public ResponseResult selectLink(Long pageNum,Long pageSize,String name,String status) {
        return linkService.selectLink(pageNum,pageSize,name,status);
    }

    @PostMapping()
    public ResponseResult insertLink(@RequestBody Link link) {
        linkService.save(link);
        return ResponseResult.okResult();
    }
    @GetMapping("/{id}")
    public ResponseResult selectLink(@PathVariable String id){
        Link link = linkService.getById(id);
        return ResponseResult.okResult(link);
    }

    @PutMapping()
    public ResponseResult updateLink(@RequestBody Link link){
        linkService.updateById(link);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteLink(@PathVariable Long id){
        linkService.removeById(id);
        return ResponseResult.okResult();
    }
}
